<?php
require '/config.php';
require '/include.php';

if (!empty($_GET['type']) && !empty($_GET['item'])){

	$rate = $_GET['type'] == 'up' ? 1 : 0;
	$item = $_GET['item'];

	try{
		if (!isSubmitted($item)){

			if (addRating($item, $rate)){
				echo json_encode(array(
						'error'=>false
				));
			}else{
				echo json_encode(array(
						'error'=>true,
						'case'=>4
				));
			}

		}else{
			echo json_encode(array(
					'error'=>true,
					'case'=>3
			));
		}

	}catch (Exception $e){
		echo json_encode(array(
				'error'=>true,
				'case'=>2
		));
	}

}else{
	echo json_encode(array(
			'error'=>true,
			'case'=>1
	));
}